import 'dart:async';

import 'package:event_bus/event_bus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hong_vpn_new_20240626/hvn_tools/hvn_channel_manager.dart';
import 'package:hong_vpn_new_20240626/hvn_tools/vpn_manager.dart';
import 'package:intl/intl.dart';

import 'api.dart';
import 'global.dart';

zzLog(String? message, {int? wrapWidth}) {
  debugPrint(message, wrapWidth: wrapWidth);
}

EventBus eventBus = EventBus();

class Utils {
  static Future<void> initConfig({required Function(double) progress}) async {
    Global.ovpnStatus.addListen();
    HVNChannelManager.share.ovpnPrepare();

    Global.reloadIsReadPrivacy();

    progress(0.2);
    await HVNChannelManager.share.requestTrackingAuthorization();
    progress(0.4);
    try {
      await API.reloadVpnList();
      // ignore: empty_catches
    } catch (e) {}
    progress(0.6);

    await VpnManager.share.init();
    progress(0.8);
  }

  static String getCurrentTime() {
    final now = DateTime.now();
    final formatter = DateFormat('yyyy/MM/dd HH:mm:ss');
    final formattedTime = formatter.format(now);

    return formattedTime;
  }
}
